package com.yl.mine.fragment

import com.yl.common.base.BaseVMFragment
import com.yl.mine.viewmodel.MineViewModel
import com.yl.mine.R
import com.yl.mine.databinding.FragmentMineBinding
import org.koin.androidx.viewmodel.ext.android.viewModel

class MineFragment : BaseVMFragment<FragmentMineBinding>() {
    private val mineViewModel: MineViewModel by viewModel()

//    private val BANNER_TYPE = "banner2"
//    private var mNextPageUrl: String? = null
//    lateinit var mAdapter: MineAdapter
//    lateinit var lm: LinearLayoutManager
//    var isLoadMore = false
//    private var bannerList = ArrayList<DailyModel.Issue.Item>()
//    private var dailyList = ArrayList<DailyModel.Issue.Item>()
//
    override fun getLayoutID(): Int = R.layout.fragment_mine

    private fun initTitle() {
        mBind.mineTitle.title.text = "我的"
    }

    override fun observe() {
//        mineViewModel.bannerList.observe(this, object : BaseStateObserver<DailyModel>(null) {
//            override fun getRespDataSuccess(bannerModel: BaseResp<DailyModel>) {
//                super.getRespDataSuccess(bannerModel)
//                Log.e(TAG, "bannerList=${bannerModel.toString()}")
//                mNextPageUrl = bannerModel.nextPageUrl
//                val list = bannerModel.issueList!![0].itemList
//                bannerList.addAll(list)
//                bannerList.removeAll {
//                    it.type == BANNER_TYPE
//                }
//                mAdapter.setBannerData(bannerList)
//                mineViewModel.getDailyList(mNextPageUrl!!)
//            }
//
//            override fun getRespDataEnd() {
//                super.getRespDataEnd()
//                Log.e(TAG, "getRespDataEnd")
//            }
//
//        })
//
//        mineViewModel.dailyList.observe(this, object : BaseStateObserver<DailyModel>(null) {
//            override fun getRespDataSuccess(dailyModel: BaseResp<DailyModel>) {
//                super.getRespDataSuccess(dailyModel)
//
//                Log.e(TAG, "dailyList=${dailyModel.toString()}")
//                mNextPageUrl = dailyModel.nextPageUrl
//                val list = dailyModel.issueList!![0].itemList
//                dailyList.addAll(list)
//                dailyList.removeAll {
//                    it.type == BANNER_TYPE
//                }
//                mAdapter.setData(dailyList)
//
//                resetUI()
//            }
//
//            override fun getRespDataEnd() {
//                super.getRespDataEnd()
//                Log.e(TAG, "dailyList   End")
//            }
//
//        })
    }

    override fun init() {
        initTitle()
//        initRecyclerView()
//        mineViewModel.getBanner()
    }

//    private fun initRecyclerView() {
//        lm = LinearLayoutManager(activity)
//        mBind.recyclerView.layoutManager = lm
//
//        mAdapter = MineAdapter(object : MineItemClickListener {
//            override fun onItemClick(position: Int) {
//                val data = dailyList[position]
//                Log.e(TAG, "onItemClick   ${position}")
//                ToastUtil.showMsg("跳转")
//                val intent = Intent(activity, PlayVideoActivity::class.java)
//                val bundle = Bundle()
//                bundle.putString("data", Gson().toJson(data))
//                intent.putExtra("Message", bundle)
//                startActivity(intent)
//            }
//
//            override fun onCollectClick(position: Int) {
//                ToastUtil.showMsg("分享")
//            }
//
//        })
//
//        mBind.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
//            override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
//                if (newState == RecyclerView.SCROLL_STATE_IDLE && mAdapter.itemCount != 0 &&
//                    (lm.findLastVisibleItemPosition() + 1) == mAdapter.itemCount && !isLoadMore && !mAdapter.isLastPage
//                ) {
//                    Log.d(TAG, "onScrollStateChanged: last-----")
//                    isLoadMore = true
////                    homeViewModel.getMaidan(currentPage + 1)
//                }
//            }
//        })
//
//
//        mBind.swipeLayout.setColorSchemeResources(R.color.theme_color)
//        mBind.swipeLayout.setOnRefreshListener {
//            mAdapter.isLastPage = false
//            getHomeData()
//        }
//    }

//    private fun getHomeData() {
//        mineViewModel.getBanner()
//    }

//    private fun resetUI() {
//        mBind.recyclerView.adapter = mAdapter
//        isLoadMore = false//加载更多完成，重置false
//        if (mBind.swipeLayout.isRefreshing) {
//            mBind.swipeLayout.isRefreshing = false
//        }
//    }
}